{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>n_siblings_spouses</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>class</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>Third</td>\n",
       "      <td>unknown</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>n</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>First</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>n</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>Third</td>\n",
       "      <td>unknown</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>First</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>n</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>male</td>\n",
       "      <td>28.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.4583</td>\n",
       "      <td>Third</td>\n",
       "      <td>unknown</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>y</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived     sex   age  n_siblings_spouses  parch     fare  class     deck  \\\n",
       "0         0    male  22.0                   1      0   7.2500  Third  unknown   \n",
       "1         1  female  38.0                   1      0  71.2833  First        C   \n",
       "2         1  female  26.0                   0      0   7.9250  Third  unknown   \n",
       "3         1  female  35.0                   1      0  53.1000  First        C   \n",
       "4         0    male  28.0                   0      0   8.4583  Third  unknown   \n",
       "\n",
       "   embark_town alone  \n",
       "0  Southampton     n  \n",
       "1    Cherbourg     n  \n",
       "2  Southampton     y  \n",
       "3  Southampton     n  \n",
       "4   Queenstown     y  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from __future__ import absolute_import, division, print_function, unicode_literals\n",
    "import pandas as pd\n",
    "import tensorflow as tf\n",
    "\n",
    "eval_data = pd.read_csv(\"eval.csv\")\n",
    "eval_data_len = len(eval_data)\n",
    "train_data = pd.read_csv(\"train.csv\")\n",
    "train_data_len = len(train_data)\n",
    "all_data = train_data.append(eval_data)\n",
    "train_data.head()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "survived                int64\n",
      "sex                      int8\n",
      "age                   float32\n",
      "n_siblings_spouses      int64\n",
      "parch                   int64\n",
      "fare                  float32\n",
      "class                    int8\n",
      "deck                     int8\n",
      "embark_town              int8\n",
      "alone                    int8\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "#将所有的字符转换为离散值 \n",
    "\n",
    "all_data[\"sex\"]=pd.Categorical(all_data[\"sex\"]).codes\n",
    "all_data[\"class\"] = pd.Categorical(all_data[\"class\"]).codes\n",
    "all_data[\"deck\"]=pd.Categorical(all_data[\"deck\"]).codes\n",
    "all_data[\"embark_town\"] = pd.Categorical(all_data[\"embark_town\"]).codes\n",
    "all_data[\"alone\"] = pd.Categorical(all_data[\"alone\"]).codes\n",
    "all_data[\"age\"] = all_data[\"age\"].astype('float32')\n",
    "all_data[\"fare\"] = all_data[\"fare\"].astype('float32')\n",
    "#all_data[\"survived\"] = all_data[\"survived\"].astype('int8')\n",
    "\n",
    "print(all_data.dtypes)\n",
    "train_data =  all_data.head(train_data_len)\n",
    "eval_data = all_data.tail(eval_data_len)\n",
    "test_data = eval_data.sample(frac=0.1)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0  1\n",
       "0  1  0\n",
       "1  0  1\n",
       "2  0  1\n",
       "3  0  1\n",
       "4  1  0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#trian_data  = trian_data.pop(\"age\")\n",
    "\n",
    "target_train_data = train_data.pop(\"survived\")\n",
    "target_eval_data = eval_data.pop(\"survived\")\n",
    "target_test_data = test_data.pop(\"survived\")\n",
    "\n",
    "target_train_data_hard_code =  target_train_data.astype('int8')\n",
    "target_eval_data_hard_code =  target_eval_data.astype('int8')\n",
    "target_test_data_hard_code =  target_test_data.astype('int8')\n",
    "\n",
    "target_train_data_one_hot = pd.get_dummies(target_train_data)\n",
    "target_eval_data_one_hot = pd.get_dummies(target_eval_data)\n",
    "target_test_data_one_hot = pd.get_dummies(target_test_data)\n",
    "\n",
    "target_train_data_one_hot.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>n_siblings_spouses</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>class</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.250000</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.283302</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.925000</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.099998</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>28.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.458300</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   sex   age  n_siblings_spouses  parch       fare  class  deck  embark_town  \\\n",
       "0    1  22.0                   1      0   7.250000      2     7            2   \n",
       "1    0  38.0                   1      0  71.283302      0     2            0   \n",
       "2    0  26.0                   0      0   7.925000      2     7            2   \n",
       "3    0  35.0                   1      0  53.099998      0     2            2   \n",
       "4    1  28.0                   0      0   8.458300      2     7            1   \n",
       "\n",
       "   alone  \n",
       "0      0  \n",
       "1      0  \n",
       "2      1  \n",
       "3      0  \n",
       "4      1  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>n_siblings_spouses</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>class</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.050000</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>54.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>51.862499</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>58.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.549999</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>55.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>34.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   sex   age  n_siblings_spouses  parch       fare  class  deck  embark_town  \\\n",
       "0    1  35.0                   0      0   8.050000      2     7            2   \n",
       "1    1  54.0                   0      0  51.862499      0     4            2   \n",
       "2    0  58.0                   0      0  26.549999      0     2            2   \n",
       "3    0  55.0                   0      0  16.000000      1     7            2   \n",
       "4    1  34.0                   0      0  13.000000      1     3            2   \n",
       "\n",
       "   alone  \n",
       "0      1  \n",
       "1      1  \n",
       "2      1  \n",
       "3      1  \n",
       "4      1  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>n_siblings_spouses</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>class</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>252</th>\n",
       "      <td>0</td>\n",
       "      <td>44.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>11.1333</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>217</th>\n",
       "      <td>1</td>\n",
       "      <td>31.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>226</th>\n",
       "      <td>1</td>\n",
       "      <td>16.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.7750</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>24.1500</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     sex   age  n_siblings_spouses  parch     fare  class  deck  embark_town  \\\n",
       "252    0  44.0                   1      0  26.0000      1     7            2   \n",
       "45     0   1.0                   1      1  11.1333      2     7            2   \n",
       "217    1  31.0                   0      0   7.9250      2     7            2   \n",
       "226    1  16.0                   0      0   7.7750      2     7            2   \n",
       "115    0  10.0                   0      2  24.1500      2     7            2   \n",
       "\n",
       "     alone  \n",
       "252      0  \n",
       "45       0  \n",
       "217      1  \n",
       "226      1  \n",
       "115      0  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Feature:[ 1.   22.    1.    0.    7.25  2.    7.    2.    0.  ], Target:0\n",
      "Feature:[ 0.         38.          1.          0.         71.28330231  0.\n",
      "  2.          0.          0.        ], Target:1\n",
      "Feature:[ 0.         26.          0.          0.          7.92500019  2.\n",
      "  7.          2.          1.        ], Target:1\n",
      "Feature:[ 0.         35.          1.          0.         53.09999847  0.\n",
      "  2.          2.          0.        ], Target:1\n",
      "Feature:[ 1.         28.          0.          0.          8.45829964  2.\n",
      "  7.          1.          1.        ], Target:0\n"
     ]
    }
   ],
   "source": [
    "# 开始使用dataset切片数据\n",
    "dataset_train_hard_code = tf.data.Dataset.from_tensor_slices((train_data.values, target_train_data_hard_code.values))\n",
    "dataset_evaluation_hard_code = tf.data.Dataset.from_tensor_slices((eval_data.values, target_eval_data_hard_code.values))\n",
    "dataset_test_hard_code = tf.data.Dataset.from_tensor_slices((test_data.values, target_test_data_hard_code.values))\n",
    "\n",
    "dataset_train_one_hot = tf.data.Dataset.from_tensor_slices((train_data.values, target_train_data_one_hot.values))\n",
    "dataset_evaluation_one_hot = tf.data.Dataset.from_tensor_slices((eval_data.values, target_eval_data_one_hot.values))\n",
    "dataset_test_one_hot = tf.data.Dataset.from_tensor_slices((test_data.values, target_test_data_one_hot.values))\n",
    "# 打印出来看看结果\n",
    "for feat,targ in dataset_train_hard_code.take(5):\n",
    "    print('Feature:{}, Target:{}'.format(feat,targ))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Layer sequential is casting an input tensor from dtype float64 to the layer's dtype of float32, which is new behavior in TensorFlow 2.  The layer has dtype float32 because it's dtype defaults to floatx.\n",
      "\n",
      "If you intended to run this layer in float32, you can safely ignore this warning. If in doubt, this warning is likely only an issue if you are porting a TensorFlow 1.X model to TensorFlow 2.\n",
      "\n",
      "To change all layers to have dtype float64 by default, call `tf.keras.backend.set_floatx('float64')`. To change just this layer, pass dtype='float64' to the layer constructor. If you are the author of this layer, you can disable autocasting by passing autocast=False to the base Layer constructor.\n",
      "\n",
      "Epoch 1/100\n",
      "40/40 [==============================] - 2s 52ms/step - loss: 2.3745 - accuracy: 0.3876 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00\n",
      "Epoch 2/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.9047 - accuracy: 0.5750 - val_loss: 0.7185 - val_accuracy: 0.6477\n",
      "Epoch 3/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.7382 - accuracy: 0.6427 - val_loss: 0.6489 - val_accuracy: 0.6591\n",
      "Epoch 4/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.6723 - accuracy: 0.6563 - val_loss: 0.6264 - val_accuracy: 0.6705\n",
      "Epoch 5/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.6335 - accuracy: 0.6826 - val_loss: 0.6144 - val_accuracy: 0.6894\n",
      "Epoch 6/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.6035 - accuracy: 0.7041 - val_loss: 0.6105 - val_accuracy: 0.6856\n",
      "Epoch 7/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5971 - accuracy: 0.7089 - val_loss: 0.6100 - val_accuracy: 0.6894\n",
      "Epoch 8/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5856 - accuracy: 0.7137 - val_loss: 0.6083 - val_accuracy: 0.6894\n",
      "Epoch 9/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5811 - accuracy: 0.7241 - val_loss: 0.5863 - val_accuracy: 0.6970\n",
      "Epoch 10/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5737 - accuracy: 0.7305 - val_loss: 0.6083 - val_accuracy: 0.7008\n",
      "Epoch 11/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5688 - accuracy: 0.7329 - val_loss: 0.6047 - val_accuracy: 0.7008\n",
      "Epoch 12/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5643 - accuracy: 0.7368 - val_loss: 0.5946 - val_accuracy: 0.7083\n",
      "Epoch 13/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5588 - accuracy: 0.7424 - val_loss: 0.5821 - val_accuracy: 0.7197\n",
      "Epoch 14/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5534 - accuracy: 0.7392 - val_loss: 0.5979 - val_accuracy: 0.7121\n",
      "Epoch 15/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5477 - accuracy: 0.7400 - val_loss: 0.5789 - val_accuracy: 0.7159\n",
      "Epoch 16/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5463 - accuracy: 0.7400 - val_loss: 0.5806 - val_accuracy: 0.7235\n",
      "Epoch 17/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5378 - accuracy: 0.7456 - val_loss: 0.5903 - val_accuracy: 0.7311\n",
      "Epoch 18/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5329 - accuracy: 0.7416 - val_loss: 0.5650 - val_accuracy: 0.7235\n",
      "Epoch 19/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5318 - accuracy: 0.7416 - val_loss: 0.5838 - val_accuracy: 0.7235\n",
      "Epoch 20/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5252 - accuracy: 0.7408 - val_loss: 0.5626 - val_accuracy: 0.7311\n",
      "Epoch 21/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5223 - accuracy: 0.7440 - val_loss: 0.5419 - val_accuracy: 0.7273\n",
      "Epoch 22/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5178 - accuracy: 0.7488 - val_loss: 0.5690 - val_accuracy: 0.7235\n",
      "Epoch 23/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5077 - accuracy: 0.7528 - val_loss: 0.5364 - val_accuracy: 0.7273\n",
      "Epoch 24/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5044 - accuracy: 0.7504 - val_loss: 0.5326 - val_accuracy: 0.7235\n",
      "Epoch 25/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4983 - accuracy: 0.7695 - val_loss: 0.5397 - val_accuracy: 0.7311\n",
      "Epoch 26/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4916 - accuracy: 0.7648 - val_loss: 0.5070 - val_accuracy: 0.7235\n",
      "Epoch 27/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4873 - accuracy: 0.7663 - val_loss: 0.5192 - val_accuracy: 0.7538\n",
      "Epoch 28/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4795 - accuracy: 0.7656 - val_loss: 0.5100 - val_accuracy: 0.7500\n",
      "Epoch 29/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4774 - accuracy: 0.7656 - val_loss: 0.5020 - val_accuracy: 0.7576\n",
      "Epoch 30/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4718 - accuracy: 0.7679 - val_loss: 0.5377 - val_accuracy: 0.7424\n",
      "Epoch 31/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4703 - accuracy: 0.7831 - val_loss: 0.5454 - val_accuracy: 0.7386\n",
      "Epoch 32/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4658 - accuracy: 0.7807 - val_loss: 0.5053 - val_accuracy: 0.7689\n",
      "Epoch 33/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4598 - accuracy: 0.7815 - val_loss: 0.5195 - val_accuracy: 0.7614\n",
      "Epoch 34/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4564 - accuracy: 0.7863 - val_loss: 0.5299 - val_accuracy: 0.7462\n",
      "Epoch 35/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4570 - accuracy: 0.7879 - val_loss: 0.5516 - val_accuracy: 0.7538\n",
      "Epoch 36/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4476 - accuracy: 0.7959 - val_loss: 0.5039 - val_accuracy: 0.7500\n",
      "Epoch 37/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4466 - accuracy: 0.7982 - val_loss: 0.5207 - val_accuracy: 0.7538\n",
      "Epoch 38/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4459 - accuracy: 0.8006 - val_loss: 0.5194 - val_accuracy: 0.7500\n",
      "Epoch 39/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4447 - accuracy: 0.8070 - val_loss: 0.4843 - val_accuracy: 0.7500\n",
      "Epoch 40/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4382 - accuracy: 0.8014 - val_loss: 0.5164 - val_accuracy: 0.7462\n",
      "Epoch 41/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4388 - accuracy: 0.8022 - val_loss: 0.5004 - val_accuracy: 0.7652\n",
      "Epoch 42/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4371 - accuracy: 0.8030 - val_loss: 0.4905 - val_accuracy: 0.7765\n",
      "Epoch 43/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4395 - accuracy: 0.7974 - val_loss: 0.4875 - val_accuracy: 0.7538\n",
      "Epoch 44/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4270 - accuracy: 0.8094 - val_loss: 0.4953 - val_accuracy: 0.7500\n",
      "Epoch 45/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4294 - accuracy: 0.8062 - val_loss: 0.4990 - val_accuracy: 0.7538\n",
      "Epoch 46/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4289 - accuracy: 0.8118 - val_loss: 0.5290 - val_accuracy: 0.7538\n",
      "Epoch 47/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4276 - accuracy: 0.8102 - val_loss: 0.4979 - val_accuracy: 0.7576\n",
      "Epoch 48/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4300 - accuracy: 0.8134 - val_loss: 0.4923 - val_accuracy: 0.7614\n",
      "Epoch 49/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4203 - accuracy: 0.8070 - val_loss: 0.4936 - val_accuracy: 0.7576\n",
      "Epoch 50/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4230 - accuracy: 0.8134 - val_loss: 0.5029 - val_accuracy: 0.7576\n",
      "Epoch 51/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4232 - accuracy: 0.8038 - val_loss: 0.5133 - val_accuracy: 0.7576\n",
      "Epoch 52/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4193 - accuracy: 0.8086 - val_loss: 0.4974 - val_accuracy: 0.7500\n",
      "Epoch 53/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4169 - accuracy: 0.8142 - val_loss: 0.5024 - val_accuracy: 0.7652\n",
      "Epoch 54/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4185 - accuracy: 0.8110 - val_loss: 0.5077 - val_accuracy: 0.7538\n",
      "Epoch 55/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4132 - accuracy: 0.8182 - val_loss: 0.5039 - val_accuracy: 0.7614\n",
      "Epoch 56/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4163 - accuracy: 0.8078 - val_loss: 0.5114 - val_accuracy: 0.7576\n",
      "Epoch 57/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4172 - accuracy: 0.8166 - val_loss: 0.4896 - val_accuracy: 0.7500\n",
      "Epoch 58/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4120 - accuracy: 0.8142 - val_loss: 0.4997 - val_accuracy: 0.7500\n",
      "Epoch 59/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4168 - accuracy: 0.8126 - val_loss: 0.5415 - val_accuracy: 0.7614\n",
      "Epoch 60/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4111 - accuracy: 0.8142 - val_loss: 0.4840 - val_accuracy: 0.7500\n",
      "Epoch 61/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4137 - accuracy: 0.8118 - val_loss: 0.5009 - val_accuracy: 0.7614\n",
      "Epoch 62/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4137 - accuracy: 0.8182 - val_loss: 0.5130 - val_accuracy: 0.7727\n",
      "Epoch 63/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4133 - accuracy: 0.8150 - val_loss: 0.4722 - val_accuracy: 0.7576\n",
      "Epoch 64/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4158 - accuracy: 0.8238 - val_loss: 0.4942 - val_accuracy: 0.7424\n",
      "Epoch 65/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4072 - accuracy: 0.8206 - val_loss: 0.5355 - val_accuracy: 0.7538\n",
      "Epoch 66/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4059 - accuracy: 0.8198 - val_loss: 0.5097 - val_accuracy: 0.7727\n",
      "Epoch 67/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4070 - accuracy: 0.8166 - val_loss: 0.5237 - val_accuracy: 0.7689\n",
      "Epoch 68/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4124 - accuracy: 0.8198 - val_loss: 0.4839 - val_accuracy: 0.7424\n",
      "Epoch 69/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4056 - accuracy: 0.8158 - val_loss: 0.5142 - val_accuracy: 0.7727\n",
      "Epoch 70/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4045 - accuracy: 0.8214 - val_loss: 0.5044 - val_accuracy: 0.7538\n",
      "Epoch 71/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4087 - accuracy: 0.8166 - val_loss: 0.5040 - val_accuracy: 0.7500\n",
      "Epoch 72/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4040 - accuracy: 0.8190 - val_loss: 0.4935 - val_accuracy: 0.7462\n",
      "Epoch 73/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4054 - accuracy: 0.8166 - val_loss: 0.5410 - val_accuracy: 0.7614\n",
      "Epoch 74/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4054 - accuracy: 0.8190 - val_loss: 0.4895 - val_accuracy: 0.7500\n",
      "Epoch 75/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4053 - accuracy: 0.8174 - val_loss: 0.4941 - val_accuracy: 0.7500\n",
      "Epoch 76/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4032 - accuracy: 0.8238 - val_loss: 0.4897 - val_accuracy: 0.7652\n",
      "Epoch 77/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4022 - accuracy: 0.8270 - val_loss: 0.5090 - val_accuracy: 0.7652\n",
      "Epoch 78/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4078 - accuracy: 0.8150 - val_loss: 0.4911 - val_accuracy: 0.7614\n",
      "Epoch 79/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4052 - accuracy: 0.8142 - val_loss: 0.4891 - val_accuracy: 0.7500\n",
      "Epoch 80/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4022 - accuracy: 0.8190 - val_loss: 0.5009 - val_accuracy: 0.7576\n",
      "Epoch 81/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4050 - accuracy: 0.8198 - val_loss: 0.5612 - val_accuracy: 0.7652\n",
      "Epoch 82/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4035 - accuracy: 0.8230 - val_loss: 0.5021 - val_accuracy: 0.7500\n",
      "Epoch 83/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4076 - accuracy: 0.8150 - val_loss: 0.4830 - val_accuracy: 0.7538\n",
      "Epoch 84/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4091 - accuracy: 0.8174 - val_loss: 0.5844 - val_accuracy: 0.7614\n",
      "Epoch 85/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4036 - accuracy: 0.8198 - val_loss: 0.5228 - val_accuracy: 0.7652\n",
      "Epoch 86/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4041 - accuracy: 0.8118 - val_loss: 0.5189 - val_accuracy: 0.7576\n",
      "Epoch 87/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.3948 - accuracy: 0.8238 - val_loss: 0.4921 - val_accuracy: 0.7576\n",
      "Epoch 88/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.3997 - accuracy: 0.8262 - val_loss: 0.4750 - val_accuracy: 0.7576\n",
      "Epoch 89/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4002 - accuracy: 0.8230 - val_loss: 0.4832 - val_accuracy: 0.7689\n",
      "Epoch 90/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.3979 - accuracy: 0.8222 - val_loss: 0.5313 - val_accuracy: 0.7576\n",
      "Epoch 91/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.3984 - accuracy: 0.8254 - val_loss: 0.5036 - val_accuracy: 0.7652\n",
      "Epoch 92/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.3969 - accuracy: 0.8238 - val_loss: 0.4751 - val_accuracy: 0.7652\n",
      "Epoch 93/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.3993 - accuracy: 0.8246 - val_loss: 0.5289 - val_accuracy: 0.7652\n",
      "Epoch 94/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.3974 - accuracy: 0.8230 - val_loss: 0.5095 - val_accuracy: 0.7614\n",
      "Epoch 95/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4001 - accuracy: 0.8230 - val_loss: 0.4966 - val_accuracy: 0.7576\n",
      "Epoch 96/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.3952 - accuracy: 0.8222 - val_loss: 0.5093 - val_accuracy: 0.7576\n",
      "Epoch 97/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.3989 - accuracy: 0.8246 - val_loss: 0.5011 - val_accuracy: 0.7538\n",
      "Epoch 98/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.3991 - accuracy: 0.8190 - val_loss: 0.4815 - val_accuracy: 0.7652\n",
      "Epoch 99/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.3951 - accuracy: 0.8254 - val_loss: 0.4867 - val_accuracy: 0.7614\n",
      "Epoch 100/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.3961 - accuracy: 0.8278 - val_loss: 0.5022 - val_accuracy: 0.7614\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<tensorflow.python.keras.callbacks.History at 0x15183e2e2e8>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_dataset = dataset_train_hard_code.repeat(2).\\\n",
    "                shuffle(2*len(train_data)).batch(32)\n",
    "def get_compiled_model_hard_code():\n",
    "  model = tf.keras.Sequential([\n",
    "    tf.keras.layers.Dense(10, activation='relu'),\n",
    "    tf.keras.layers.Dense(10, activation='relu'),\n",
    "    tf.keras.layers.Dense(1, activation='sigmoid')\n",
    "  ])\n",
    "\n",
    "  model.compile(optimizer='adam',\n",
    "                loss='binary_crossentropy',\n",
    "                metrics=['accuracy'])\n",
    "  return model\n",
    "\n",
    "\n",
    "model_hard_code = get_compiled_model_hard_code()\n",
    "model_hard_code.fit(train_dataset, validation_data=dataset_evaluation_hard_code.shuffle(50).batch(50),epochs=100)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "26/26 [==============================] - 0s 16ms/step - loss: 0.6524 - accuracy: 0.7308\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[0.6523873296637948, 0.7307692]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#dataset_evaluation = dataset_evaluation.shuffle(len(eval_data)).batch(1)\n",
    "model_hard_code.evaluate(dataset_test_hard_code.batch(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(26, 1)\n"
     ]
    }
   ],
   "source": [
    "y_predict = model_hard_code.predict(test_data.values)\n",
    "print(y_predict.shape)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Layer sequential_1 is casting an input tensor from dtype float64 to the layer's dtype of float32, which is new behavior in TensorFlow 2.  The layer has dtype float32 because it's dtype defaults to floatx.\n",
      "\n",
      "If you intended to run this layer in float32, you can safely ignore this warning. If in doubt, this warning is likely only an issue if you are porting a TensorFlow 1.X model to TensorFlow 2.\n",
      "\n",
      "To change all layers to have dtype float64 by default, call `tf.keras.backend.set_floatx('float64')`. To change just this layer, pass dtype='float64' to the layer constructor. If you are the author of this layer, you can disable autocasting by passing autocast=False to the base Layer constructor.\n",
      "\n",
      "Epoch 1/100\n",
      "40/40 [==============================] - 1s 28ms/step - loss: 3.2571 - accuracy: 0.5223 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00\n",
      "Epoch 2/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 1.7810 - accuracy: 0.5108 - val_loss: 1.4729 - val_accuracy: 0.4962\n",
      "Epoch 3/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 1.1960 - accuracy: 0.5020 - val_loss: 1.0958 - val_accuracy: 0.4773\n",
      "Epoch 4/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.9954 - accuracy: 0.4980 - val_loss: 0.9949 - val_accuracy: 0.4830\n",
      "Epoch 5/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.8895 - accuracy: 0.5020 - val_loss: 0.8688 - val_accuracy: 0.4962\n",
      "Epoch 6/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.8205 - accuracy: 0.5100 - val_loss: 0.8114 - val_accuracy: 0.5057\n",
      "Epoch 7/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.7710 - accuracy: 0.5140 - val_loss: 0.7587 - val_accuracy: 0.5019\n",
      "Epoch 8/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.7380 - accuracy: 0.5156 - val_loss: 0.7349 - val_accuracy: 0.5246\n",
      "Epoch 9/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.7115 - accuracy: 0.5474 - val_loss: 0.7008 - val_accuracy: 0.5511\n",
      "Epoch 10/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.6888 - accuracy: 0.5937 - val_loss: 0.6775 - val_accuracy: 0.5871\n",
      "Epoch 11/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.6673 - accuracy: 0.6200 - val_loss: 0.6547 - val_accuracy: 0.6553\n",
      "Epoch 12/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.6504 - accuracy: 0.6571 - val_loss: 0.6200 - val_accuracy: 0.6686\n",
      "Epoch 13/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.6310 - accuracy: 0.6675 - val_loss: 0.6179 - val_accuracy: 0.6742\n",
      "Epoch 14/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.6188 - accuracy: 0.6786 - val_loss: 0.5874 - val_accuracy: 0.6875\n",
      "Epoch 15/100\n",
      "40/40 [==============================] - 0s 10ms/step - loss: 0.6118 - accuracy: 0.6850 - val_loss: 0.6043 - val_accuracy: 0.6932\n",
      "Epoch 16/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.6056 - accuracy: 0.6890 - val_loss: 0.5897 - val_accuracy: 0.7027\n",
      "Epoch 17/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.6018 - accuracy: 0.6854 - val_loss: 0.5865 - val_accuracy: 0.7008\n",
      "Epoch 18/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.5950 - accuracy: 0.6914 - val_loss: 0.5911 - val_accuracy: 0.6970\n",
      "Epoch 19/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.5924 - accuracy: 0.6878 - val_loss: 0.5594 - val_accuracy: 0.6989\n",
      "Epoch 20/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5882 - accuracy: 0.6930 - val_loss: 0.5800 - val_accuracy: 0.6932\n",
      "Epoch 21/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.5840 - accuracy: 0.6934 - val_loss: 0.5683 - val_accuracy: 0.6989\n",
      "Epoch 22/100\n",
      "40/40 [==============================] - 0s 9ms/step - loss: 0.5801 - accuracy: 0.6934 - val_loss: 0.5613 - val_accuracy: 0.7008\n",
      "Epoch 23/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.5751 - accuracy: 0.6954 - val_loss: 0.5655 - val_accuracy: 0.6875\n",
      "Epoch 24/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.5721 - accuracy: 0.6982 - val_loss: 0.5588 - val_accuracy: 0.6894\n",
      "Epoch 25/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5676 - accuracy: 0.6954 - val_loss: 0.5601 - val_accuracy: 0.6837\n",
      "Epoch 26/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.5614 - accuracy: 0.6982 - val_loss: 0.5369 - val_accuracy: 0.6875\n",
      "Epoch 27/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5587 - accuracy: 0.7045 - val_loss: 0.5562 - val_accuracy: 0.7027\n",
      "Epoch 28/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5564 - accuracy: 0.7121 - val_loss: 0.5447 - val_accuracy: 0.6970\n",
      "Epoch 29/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5500 - accuracy: 0.7117 - val_loss: 0.5388 - val_accuracy: 0.6989\n",
      "Epoch 30/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5443 - accuracy: 0.7165 - val_loss: 0.5498 - val_accuracy: 0.7102\n",
      "Epoch 31/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5431 - accuracy: 0.7245 - val_loss: 0.5308 - val_accuracy: 0.6913\n",
      "Epoch 32/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5390 - accuracy: 0.7185 - val_loss: 0.5239 - val_accuracy: 0.7083\n",
      "Epoch 33/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5378 - accuracy: 0.7177 - val_loss: 0.5419 - val_accuracy: 0.7102\n",
      "Epoch 34/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5317 - accuracy: 0.7253 - val_loss: 0.5224 - val_accuracy: 0.7121\n",
      "Epoch 35/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5281 - accuracy: 0.7261 - val_loss: 0.5292 - val_accuracy: 0.7140\n",
      "Epoch 36/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5251 - accuracy: 0.7221 - val_loss: 0.5287 - val_accuracy: 0.7159\n",
      "Epoch 37/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5199 - accuracy: 0.7257 - val_loss: 0.5183 - val_accuracy: 0.7197\n",
      "Epoch 38/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5181 - accuracy: 0.7321 - val_loss: 0.5340 - val_accuracy: 0.7121\n",
      "Epoch 39/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5163 - accuracy: 0.7305 - val_loss: 0.5151 - val_accuracy: 0.7178\n",
      "Epoch 40/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5124 - accuracy: 0.7352 - val_loss: 0.5239 - val_accuracy: 0.7159\n",
      "Epoch 41/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5089 - accuracy: 0.7325 - val_loss: 0.5102 - val_accuracy: 0.7178\n",
      "Epoch 42/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5087 - accuracy: 0.7301 - val_loss: 0.5524 - val_accuracy: 0.7254\n",
      "Epoch 43/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5045 - accuracy: 0.7309 - val_loss: 0.5348 - val_accuracy: 0.7273\n",
      "Epoch 44/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.5007 - accuracy: 0.7352 - val_loss: 0.5519 - val_accuracy: 0.7254\n",
      "Epoch 45/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5023 - accuracy: 0.7428 - val_loss: 0.5222 - val_accuracy: 0.7273\n",
      "Epoch 46/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.5001 - accuracy: 0.7360 - val_loss: 0.5355 - val_accuracy: 0.7311\n",
      "Epoch 47/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4997 - accuracy: 0.7384 - val_loss: 0.5082 - val_accuracy: 0.7330\n",
      "Epoch 48/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4942 - accuracy: 0.7412 - val_loss: 0.5141 - val_accuracy: 0.7292\n",
      "Epoch 49/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4947 - accuracy: 0.7472 - val_loss: 0.5447 - val_accuracy: 0.7386\n",
      "Epoch 50/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4922 - accuracy: 0.7468 - val_loss: 0.5348 - val_accuracy: 0.7159\n",
      "Epoch 51/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4879 - accuracy: 0.7504 - val_loss: 0.5371 - val_accuracy: 0.7311\n",
      "Epoch 52/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4880 - accuracy: 0.7464 - val_loss: 0.5437 - val_accuracy: 0.7330\n",
      "Epoch 53/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4854 - accuracy: 0.7576 - val_loss: 0.5065 - val_accuracy: 0.7348\n",
      "Epoch 54/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4879 - accuracy: 0.7552 - val_loss: 0.5201 - val_accuracy: 0.7330\n",
      "Epoch 55/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4847 - accuracy: 0.7572 - val_loss: 0.5214 - val_accuracy: 0.7386\n",
      "Epoch 56/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4836 - accuracy: 0.7608 - val_loss: 0.5167 - val_accuracy: 0.7424\n",
      "Epoch 57/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4824 - accuracy: 0.7612 - val_loss: 0.5401 - val_accuracy: 0.7386\n",
      "Epoch 58/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4830 - accuracy: 0.7663 - val_loss: 0.5432 - val_accuracy: 0.7330\n",
      "Epoch 59/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4817 - accuracy: 0.7667 - val_loss: 0.5032 - val_accuracy: 0.7424\n",
      "Epoch 60/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4799 - accuracy: 0.7632 - val_loss: 0.5075 - val_accuracy: 0.7424\n",
      "Epoch 61/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4793 - accuracy: 0.7687 - val_loss: 0.5498 - val_accuracy: 0.7235\n",
      "Epoch 62/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4830 - accuracy: 0.7767 - val_loss: 0.5245 - val_accuracy: 0.7367\n",
      "Epoch 63/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4772 - accuracy: 0.7739 - val_loss: 0.5312 - val_accuracy: 0.7443\n",
      "Epoch 64/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4765 - accuracy: 0.7775 - val_loss: 0.5411 - val_accuracy: 0.7405\n",
      "Epoch 65/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4710 - accuracy: 0.7974 - val_loss: 0.5621 - val_accuracy: 0.7405\n",
      "Epoch 66/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4671 - accuracy: 0.7943 - val_loss: 0.5409 - val_accuracy: 0.7443\n",
      "Epoch 67/100\n",
      "40/40 [==============================] - 0s 9ms/step - loss: 0.4604 - accuracy: 0.7955 - val_loss: 0.5553 - val_accuracy: 0.7746\n",
      "Epoch 68/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4659 - accuracy: 0.7947 - val_loss: 0.5128 - val_accuracy: 0.7462\n",
      "Epoch 69/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4614 - accuracy: 0.8006 - val_loss: 0.5540 - val_accuracy: 0.7424\n",
      "Epoch 70/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4487 - accuracy: 0.8058 - val_loss: 0.4980 - val_accuracy: 0.7595\n",
      "Epoch 71/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4474 - accuracy: 0.8118 - val_loss: 0.5107 - val_accuracy: 0.7462\n",
      "Epoch 72/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4582 - accuracy: 0.8038 - val_loss: 0.5005 - val_accuracy: 0.7689\n",
      "Epoch 73/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4441 - accuracy: 0.8110 - val_loss: 0.4860 - val_accuracy: 0.7538\n",
      "Epoch 74/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4505 - accuracy: 0.8094 - val_loss: 0.5150 - val_accuracy: 0.7538\n",
      "Epoch 75/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4401 - accuracy: 0.8114 - val_loss: 0.5224 - val_accuracy: 0.7576\n",
      "Epoch 76/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4390 - accuracy: 0.8134 - val_loss: 0.4930 - val_accuracy: 0.7538\n",
      "Epoch 77/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4473 - accuracy: 0.8074 - val_loss: 0.5233 - val_accuracy: 0.7538\n",
      "Epoch 78/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4346 - accuracy: 0.8114 - val_loss: 0.4945 - val_accuracy: 0.7670\n",
      "Epoch 79/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4372 - accuracy: 0.8158 - val_loss: 0.5414 - val_accuracy: 0.7576\n",
      "Epoch 80/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4360 - accuracy: 0.8090 - val_loss: 0.4874 - val_accuracy: 0.7576\n",
      "Epoch 81/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4373 - accuracy: 0.8186 - val_loss: 0.5418 - val_accuracy: 0.7652\n",
      "Epoch 82/100\n",
      "40/40 [==============================] - 0s 9ms/step - loss: 0.4360 - accuracy: 0.8102 - val_loss: 0.4831 - val_accuracy: 0.7670\n",
      "Epoch 83/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4286 - accuracy: 0.8098 - val_loss: 0.4808 - val_accuracy: 0.7614\n",
      "Epoch 84/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4429 - accuracy: 0.8114 - val_loss: 0.5143 - val_accuracy: 0.7576\n",
      "Epoch 85/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4283 - accuracy: 0.8142 - val_loss: 0.4778 - val_accuracy: 0.7670\n",
      "Epoch 86/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4282 - accuracy: 0.8142 - val_loss: 0.4982 - val_accuracy: 0.7614\n",
      "Epoch 87/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4378 - accuracy: 0.8194 - val_loss: 0.5044 - val_accuracy: 0.7652\n",
      "Epoch 88/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4353 - accuracy: 0.8114 - val_loss: 0.4786 - val_accuracy: 0.7708\n",
      "Epoch 89/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4270 - accuracy: 0.8154 - val_loss: 0.4935 - val_accuracy: 0.7765\n",
      "Epoch 90/100\n",
      "40/40 [==============================] - 0s 6ms/step - loss: 0.4304 - accuracy: 0.8210 - val_loss: 0.4874 - val_accuracy: 0.7633\n",
      "Epoch 91/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4262 - accuracy: 0.8166 - val_loss: 0.5076 - val_accuracy: 0.7708\n",
      "Epoch 92/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4221 - accuracy: 0.8154 - val_loss: 0.5087 - val_accuracy: 0.7633\n",
      "Epoch 93/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4234 - accuracy: 0.8122 - val_loss: 0.5249 - val_accuracy: 0.7708\n",
      "Epoch 94/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4287 - accuracy: 0.8174 - val_loss: 0.4952 - val_accuracy: 0.7670\n",
      "Epoch 95/100\n",
      "40/40 [==============================] - 0s 8ms/step - loss: 0.4251 - accuracy: 0.8194 - val_loss: 0.4879 - val_accuracy: 0.7746\n",
      "Epoch 96/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4240 - accuracy: 0.8186 - val_loss: 0.5202 - val_accuracy: 0.7670\n",
      "Epoch 97/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4223 - accuracy: 0.8118 - val_loss: 0.5233 - val_accuracy: 0.7708\n",
      "Epoch 98/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4259 - accuracy: 0.8158 - val_loss: 0.4933 - val_accuracy: 0.7708\n",
      "Epoch 99/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4213 - accuracy: 0.8158 - val_loss: 0.4874 - val_accuracy: 0.7652\n",
      "Epoch 100/100\n",
      "40/40 [==============================] - 0s 7ms/step - loss: 0.4182 - accuracy: 0.8194 - val_loss: 0.4899 - val_accuracy: 0.7746\n",
      "26/26 [==============================] - 0s 3ms/step - loss: 0.6152 - accuracy: 0.7308\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[0.6151930158957839, 0.7307692]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def get_compiled_model_one_hot():\n",
    "  model = tf.keras.Sequential([\n",
    "    tf.keras.layers.Dense(10, activation='relu'),\n",
    "    tf.keras.layers.Dense(10, activation='relu'),\n",
    "    tf.keras.layers.Dense(2, activation='sigmoid')\n",
    "  ])\n",
    "\n",
    "  model.compile(optimizer='adam',\n",
    "                loss='binary_crossentropy',\n",
    "                metrics=['accuracy'])\n",
    "  return model\n",
    "train_dataset = dataset_train_one_hot.repeat(2).shuffle(2*len(train_data)).batch(32)\n",
    "model_one_hot = get_compiled_model_one_hot()\n",
    "model_one_hot.fit(train_dataset, validation_data=dataset_evaluation_one_hot.shuffle(50).batch(50),epochs=100)\n",
    "model_one_hot.evaluate(dataset_test_one_hot.batch(1))"
   ]
  }
 ],
 "metadata": {
  "file_extension": ".py",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
